/*
 * When the ControlButton is clicked, it bounces and shrinks to the lower-right.
 * Meanwhile, the MainMenu grows from point clicked, (0 X 0)px, transparent to a
 * full size rectangle (dictated by the size of the text). The sequence ends with
 * a subtle jog to the left. Finer tuning will result in increased user happiness.
 *
 * TODO: Set min/max size constraint.
 */

#include "MainMenu.hpp"

#include <Wt/WPopupMenuItem>
#include <Wt/WApplication>
#include <Wt/WPopupMenu>
#include <Wt/WMenuItem>
#include "utilities.hpp" // for loadStylesheet()
#include "ControlButton.hpp" // no longer needed here?

using namespace Wt;
using namespace webpages;
using namespace components;


MainMenu::MainMenu()
{
    utilities::loadStylesheet("/css/mainmenu.css"); 
    setStyleClass("mainmenu");
        
    //aboutToHide().connect(this, &MainMenu::hideSubMenu);
        
    addMenuItem("Datalogger", false);
    addMenuItem("Instruments", false);
    addMenuItem("Site", false);
    addMenuItem("Channels", false);
    addMenuItem("---", false);
    addMenuItem("Reports", false);
}

void MainMenu::addMenuItem(std::string item_name, bool enable_checkBox)
{
    if (item_name == "---")
    {
        addSeparator();
        return;
    }
    
    Wt::WPopupMenuItem* item = new Wt::WPopupMenuItem(WString::fromUTF8(item_name));
    item->setStyleClass("menuitem");
    item->setCheckable(enable_checkBox);
    //item->setIcon("resources/button-show_home.png");
    
    add(item);
}

void MainMenu::showWithAnimation()
{
    //I could not get internal animation to work so went with external CSS addStyleClass()
    //animateShow(WAnimation(WAnimation::Pop | WAnimation::Fade, WAnimation::Linear, 250));
    //setStyleClass("startanimated");

    addStyleClass("animation_settings");
}
